<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    Array.prototype.fc = function (fn) {
      let g = generator(this)
      let value, done = false;
      while (!done) {
        let item = g.next();
        value = item.value;
        done = item.done;
        if (!done) {
          fn(value);
        }
      }
    }
    const arr = [3, 4, 5, 6]

    // 实现iterator接口的函数
    function generator(collection) {
      let index = 0; // 表示遍历的数组中的元素
      let len = collection.length;
      return { // 该对象就是我们所说的遍历器对象
        next() {
          let done = index >= 0 && index < len;
          let value = collection[index];
          index += 1;
          return { value, done: !done }
        }
      }
    }

  </script>
</body>

</html>